var userImportSelect = "";
layui.use(['table', 'form', 'util'], function () {
    var table = layui.table;
    var util = layui.util;
    var form = layui.form;

    //渲染表格
    var selectUserTbIns = table.render({
        elem: '#selectUserTable',
        url: prefix + '/authUser/unallocatedList',
        initSort: {
            field: 'gmtCreate'
            , type: 'desc'
        },
        where: {
            fieldName: 'gmtCreate',
            sortType: 'desc',
            roleId: currentRole.roleId
        },
        toolbar: false,
        cols: [
            [
                {type: 'checkbox'},
                {type: 'numbers'},
                {field: 'loginName', title: '登录账号', sort: true},
                {field: 'userName', title: '用户名称', sort: true},
                {field: 'email', title: '邮箱', sort: true},
                {field: 'phoneNumber', title: '手机号'},
                {
                    field: 'status', title: '用户状态', templet: function (d) {
                        return showDictLabel(dictSysNormalDisable, d.status);
                    }, unresize: true
                },
                {
                    field: 'gmtCreate', title: '创建时间', templet: function (d) {
                        return util.toDateString(d.gmtCreate);
                    }, sort: true
                }
            ]
        ]
    });

    //表格搜索
    form.on('submit(selectUserTbSearch)', function (data) {
        selectUserTbIns.reload({where: data.field, page: {curr: 1}});
        return false;
    });

    //触发排序事件
    table.on('sort(selectUserTable)', function (obj) {
        selectUserTbIns.reload({
            initSort: obj
            , where: {
                fieldName: obj.field
                , sortType: obj.type
                , roleId: currentRole.roleId
            }
        });
    });

    //监听勾选
    table.on('checkbox(selectUserTable)', function (obj) {
        var checkStatus = table.checkStatus('selectUserTable');
        var dataList = checkStatus.data;

        var userIds = dataList.map(function (item) {
            return item.userId;
        });
        userImportSelect = userIds.join(",");
    });

});